<?php
/**
 *-----------------  （慕课网）《Yii框架》不得不说的故事  -----------------
 * Author: Zheng_Great
 * Description:  HTTP缓存的使用与学习
 * Date: 2017-03-30 13:27:24
 */

namespace frontend\controllers;
use yii;
use yii\web\Controller;
		// use frontend\controllers\YangController;

class HttpController extends Controller{

	public function behaviors(){

		return[
			[
				'class'=>'yii\filters\HttpCache',
				'only' => ['index'],
				'lastModified'=>function(){
					return filemtime('hw.txt');
					// return 1470202388;
				},
				'etagSeed'=>function(){
					$fp=fopen('hw.txt','r');
					$title=fgets($fp);
					fclose($fp);
					return $title;
					// return 'etagseed3';
				}
			]
		];

	}


	public function actionIndex(){
		// echo 'haaabbb';
		$content=file_get_contents('hw.txt');
		return $this->renderPartial('index',['new'=>$content]);
		// echo time();
	}



	public function actionCache(){
		$cache= yii::$app->cache;

		// $cache->add('key1','hello world');

		$data=$cache->get('key1');
		print_r($data);

	}


	public function actionPct(){
		echo '这都是小事';
	}

}




 ?>